import { message } from "ant-design-vue";

let currentMessage: NodeJS.Timeout | null = null;
let currentContent: string | null = null;

const showMessage = (
  type: "success" | "error" | "info" | "warning",
  content: string
) => {
  console.log("content" + currentContent + content);
  if (currentContent === content) {
    return;
  }
  currentContent = content;
  if (currentMessage) {
    clearTimeout(currentMessage);
  }
  // 显示消息并设置 onClose 回调
  message[type](content, 3, () => {
    console.log("message已关闭");
    currentContent = null; // 在消息关闭后重置 currentContent
  });
};

export const success = (content: string) => showMessage("success", content);
export const error = (content: string) => showMessage("error", content);
export const info = (content: string) => showMessage("info", content);
export const warning = (content: string) => showMessage("warning", content);
